/**
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
/*
 Copyright 2013 jQuery Foundation and other contributors
 Released under the MIT license.
 http://jquery.org/license
*/
define(["ojs/ojcore","jquery","ojs/ojcomponentcore"],function(a,g){(function(){function b(b,c,d){a:{for(var e=s[b],f=0;f<e.length;++f){var g=e[f];if(0<=d.indexOf(g))for(;;c=c.parentNode){var h=a.Components.Yc(c,g);if(h){d=h;break a}}}d=null}return d?d("option","chroming"):(a.Wc.De("oj-"+b+"-option-defaults")||{}).chroming}function c(a,b){var c=a.name,d=a.form;c?(c=c.replace(/'/g,"\\'"),c=":radio[name\x3d'"+c+"']:oj-button",d=b?b.filter(c):d?g(d).find(c):g(c,a.ownerDocument).filter(function(){return!this.form})):
d=(b?b.filter(a):g(a)).filter(":oj-button");return d}function d(a,b){a.removeClass(r).addClass(t[b])}a.Ra("oj.ojButton",g.oj.baseComponent,{defaultElement:"\x3cbutton\x3e",widgetEventPrefix:"oj",options:{chroming:"full",disabled:!1,display:"all",label:null,icons:{start:null,end:null},menu:null},Yf:function(a,b){this._super(a,b);this.Dya();"disabled"in b||this.option("disabled",!!this.element.prop("disabled"),{_context:{kb:!0}});"label"in b||(this.WJa=!0,this.option("label","inputPush"===this.type?
this.gf.val():this.gf.html(),{_context:{kb:!0}}));!this.options.menu||b.icons&&void 0!==b.icons.end||this.option("icons.end","oj-component-icon oj-button-menu-dropdown-icon",{_context:{Cd:!0,kb:!0}})},_ComponentCreate:function(){function a(){b.tV=Date.now();b.lc.removeClass(l);b.lc.removeClass("oj-hover");b.Zl()}this._super();this.element.closest("form").unbind("reset"+h).bind("reset"+h,function(){var a=g(this);setTimeout(function(){a.find(":oj-button").each(function(){g(this).data("oj-ojButton").iI(!1)}).length||
a.unbind("reset"+h)},1)});this.kG=this.eventNamespace+"menu";this.Eya();this.lZ=!!this.lc.attr("title");var b=this,c=this.SD,l=c?"":"oj-active";this.lc.addClass(k);d(this.lc,this.options.chroming);this.document.bind("touchend"+this.eventNamespace+" touchcancel"+this.eventNamespace,a);this.gf.bind("touchstart"+this.eventNamespace,function(){b.Zf()||(g(this).addClass(l),b.Zl())}).bind("touchend"+this.eventNamespace+" touchcancel"+this.eventNamespace,a).bind("mouseenter"+this.eventNamespace,function(){b.Zf()||
b.uE()||(this===e&&b.lc.addClass("oj-active"),b.lc.addClass("oj-hover").removeClass("oj-default oj-focus-only"))}).bind("mouseleave"+this.eventNamespace,function(){b.lc.removeClass("oj-hover");b.Zf()||(b.lc.removeClass(l),b.Zl())});this.z6=function(a){b.Zf()&&(a.preventDefault(),a.stopImmediatePropagation())};this.gf[0].addEventListener("click",this.z6,!0);this._focusable({element:this.lc,applyHighlight:!0,afterToggle:function(){b.Zl()}});c&&(this.element.bind("change"+this.eventNamespace,function(a){b.iI(!0);
var c=b.Uua("buttonset"),d=c&&c.y7(c.Df);c&&void 0!==d&&c.option("checked",d,{_context:{Cd:!0,originalEvent:a,kb:!0}})}),this.gf.bind("mousedown"+this.eventNamespace,function(){b.Zf()||(f=this,b.document.one("mouseup",function(){f=null}))}).bind("mouseup"+this.eventNamespace,function(){b.Zf()||this!==f||b.element.focus()}));"checkbox"===this.type?(this.gf.bind("click"+this.eventNamespace,function(){if(b.Zf())return!1}),this.element.bind("keyup"+this.eventNamespace,function(a){a.keyCode===g.ui.keyCode.ENTER&&
(b.Zf()||b.element.click())})):"radio"===this.type?(this.gf.bind("click"+this.eventNamespace,function(){if(b.Zf())return!1}),this.element.bind("keyup"+this.eventNamespace,function(a){a.keyCode!==g.ui.keyCode.ENTER||b.element[0].checked||b.Zf()||(b.element[0].checked=!0,b.element.change(),b.element.click())})):(this.gf.bind("mousedown"+this.eventNamespace,function(a){if(b.Zf())return!1;1!==a.which||b.uE()||(g(this).addClass("oj-active").removeClass("oj-default oj-focus-only"),e=this,b.document.one("mouseup",
function(){e=null}))}).bind("mouseup"+this.eventNamespace,function(){if(b.Zf())return!1;g(this).removeClass("oj-active");b.Zl()}).bind("keydown"+this.eventNamespace,function(a){if(b.Zf())return a.keyCode===g.ui.keyCode.TAB||a.keyCode===g.ui.keyCode.LEFT||a.keyCode===g.ui.keyCode.RIGHT;var c=a.keyCode===g.ui.keyCode.SPACE,d="anchor"===b.type;d&&c&&a.preventDefault();(c&&!d||a.keyCode===g.ui.keyCode.ENTER)&&g(this).addClass("oj-active").removeClass("oj-default oj-focus-only")}).bind("keyup"+this.eventNamespace+
" blur"+this.eventNamespace,function(){g(this).removeClass("oj-active");b.Zl()}),"anchor"===this.type&&(c=this.gf.attr("tabindex"),("undefined"===c||null===c||isNaN(c))&&this.gf.attr("tabindex","0")));this.options.disabled&&this.xV(!1,!0);this.IX();this.wxa();this.tda(null);this.Zl()},uE:function(){return 500>Date.now()-this.tV},ph:function(a,b,c){this.qh(b,c,{position:{of:"keyboard"===c?this.lc:b}})},Dya:function(){if(this.element.is("input[type\x3dcheckbox]"))this.type="checkbox",this.SD=!0;else if(this.element.is("input[type\x3dradio]"))this.type=
"radio",this.SD=!0;else if(this.element.is("input[type\x3dbutton],input[type\x3dsubmit],input[type\x3dreset]"))this.type="inputPush";else if(this.element.is("button"))this.type="button";else if(this.element.is("a"))this.type="anchor";else throw Error("JET Button not supported on this element type");if(this.SD){var a="label[for\x3d'"+this.element.attr("id")+"']";this.gf=this.element.siblings().filter(a)}else this.gf=this.element},Eya:function(){this.SD?(this.gf.addClass("oj-button-label"),this.element.addClass("oj-button-input oj-helper-hidden-accessible").add(this.gf).wrapAll("\x3cspan\x3e\x3c/span\x3e"),
this.lc=this.element.parent(),this.lc.addClass("oj-button-toggle"),this.element[0].checked&&this.lc.addClass("oj-selected").removeClass("oj-default oj-focus-only")):this.lc=this.element},widget:function(){return this.lc},_destroy:function(){this.eca(this.options.menu);this.document.off(this.eventNamespace);this.gf[0].removeEventListener("click",this.z6,!0);this.element.removeClass("oj-helper-hidden-accessible").removeAttr("aria-labelledby").removeUniqueId();this.options.disabled&&this.xV(!0,!1);var b=
this.SD;b||this.lc.removeClass(k+" "+l+" "+m+" "+r);this.gf.html(this.gf.find(".oj-button-text").html());b?(this.gf.removeClass("oj-button-label"),a.D.unwrap(this.element)):this.lZ||this.lc.removeAttr("title");f===this.gf[0]&&(f=null)},Gj:function(){this._super();this.Zl()},lC:function(a){this._super(a);this.IX()},IX:function(){var a=this.Zf();this.lc.toggleClass("oj-disabled",a);this.lc.toggleClass("oj-enabled",!a);"anchor"!==this.type?(this.element.prop("disabled",a),this.lc.removeAttr("aria-disabled")):
this.lc.attr("aria-disabled",a);a?(this.widget().removeClass("oj-active oj-default oj-focus-only oj-hover oj-focus oj-focus-highlight"),e=null,this.BS(this.options.menu)):this.Zl()},_setOption:function(a,b,c){var e=this.options[a];this._super(a,b,c);switch(a){case "chroming":d(this.lc,b);break;case "disabled":this.xV(e,b);this.IX();break;case "label":this.TDa();break;case "display":"inputPush"!==this.type&&this.rL();break;case "icons":this.QDa(!0);break;case "menu":this.tda(e)}},refresh:function(){this._super();
this.m4&&!this.vJ("buttonset").length&&this.lC(!1);d(this.lc,this.options.chroming)},iI:function(a){"radio"===this.type?(a?c(this.element[0]):this.element).each(function(){var a=g(this).data("oj-ojButton");this.checked?a.lc.addClass("oj-selected").removeClass("oj-default oj-focus-only"):(a.lc.removeClass("oj-selected"),a.Zl())}):"checkbox"===this.type&&(this.element[0].checked?this.lc.addClass("oj-selected").removeClass("oj-default oj-focus-only"):(this.lc.removeClass("oj-selected"),this.Zl()))},
wxa:function(){if("inputPush"===this.type)this.cda();else{var a=this.SDa(),b=this.tL(!0),c=this.tL(!1);this.rL(a,b,c)}},SDa:function(){var a=this.gf,b=g("\x3cspan class\x3d'oj-button-text'\x3e\x3c/span\x3e",this.document[0]);this.WJa?b.append(a.contents()):(a.empty(),b.text(this.options.label));"button"===this.type?(a=g("\x3cdiv\x3e\x3c/div\x3e").addClass("oj-button-label"),a.append(b),this.element.append(a)):a.append(b);if("button"===this.type||"anchor"===this.type)b.uniqueId(),this.element.attr("aria-labelledby",
b.attr("id"));return b},TDa:function(){if("inputPush"===this.type)this.cda();else{var a=this.gf.find(".oj-button-text");a.text(this.options.label);this.rL(a)}},cda:function(){this.options.label&&this.element.val(this.options.label)},QDa:function(){if("inputPush"!==this.type){var a=this.tL(!0),b=this.tL(!1);this.rL(void 0,a,b)}},tL:function(a){var b=this.gf;"button"===this.type&&(b=this.element.children("div.oj-button-label"));if(a){var c=".oj-button-icon.oj-start";a="oj-button-icon oj-start";var d=
this.options.icons.start,e="_lastStartIcon",f="prependTo"}else c=".oj-button-icon.oj-end",a="oj-button-icon oj-end",d=this.options.icons.end,e="_lastEndIcon",f="appendTo";c=b.find(c);d?(c.length?c.removeClass(this[e]):c=g("\x3cspan\x3e\x3c/span\x3e").addClass(a)[f](b),c.addClass(d)):c.remove();this[e]=d;return!!d},rL:function(a,b,c){void 0===a&&(a=this.gf.find(".oj-button-text"));void 0===b&&(b=!!this.options.icons.start);void 0===c&&(c=!!this.options.icons.end);var d=b&&c;c=b||c;var e="icons"===
this.options.display;c&&e?(a.addClass("oj-helper-hidden-accessible"),this.lZ||(a=a.text(),this.lc.attr("title",g.trim(a)))):(a.removeClass("oj-helper-hidden-accessible"),this.lZ||this.lc.removeAttr("title"));b=c?e?d?"oj-button-icons-only":"oj-button-icon-only":d?"oj-button-text-icons":b?"oj-button-text-icon-start":"oj-button-text-icon-end":"oj-button-text-only";this.lc.removeClass(m).addClass(b)},xV:function(a,b){if(!a!=!b&&"anchor"===this.type&&!this.vJ("buttonset").length&&!this.vJ("toolbar").length)if(b){var c=
this.element.attr("tabindex");this.Waa=this.xza(Number(c))?c:null;this.element.attr("tabindex",-1)}else null==this.Waa?this.element.removeAttr("tabindex"):this.element.attr("tabindex",this.Waa)},xza:function(a){return"number"===typeof a&&isFinite(a)&&Math.floor(a)===a},sDa:{buttonset:".oj-buttonset",toolbar:".oj-toolbar"},Bra:{buttonset:"ojButtonset",toolbar:"ojToolbar"},vJ:function(a){return this.lc.closest(this.sDa[a])},Uua:function(b){return(b=a.Components.Yc(this.vJ(b)[0],this.Bra[b]))&&b("instance")},
tda:function(a){if(this.options.menu&&this.element.is("input"))throw Error("Menu Button functionality is not supported on input elements.");this.eca(a);if(this.options.menu){var b=this;this.element.attr("aria-haspopup",!0).on("keydown"+this.kG,function(a){if(a.which===g.ui.keyCode.DOWN)b.Cda(a,"firstItem"),a.preventDefault();else if(a.which===g.ui.keyCode.ESCAPE){var c=b.Uqa(b.lc);b.BS(b.options.menu,a);return c}return!0}).on("click"+this.kG,function(a){var c=b.r8();c.aI||b.Cda(a,"firstItem");c.aI=
!1;a.preventDefault();return!0})}},Uqa:function(a){return!a.hasClass("oj-selected")},eca:function(a){this.element.removeAttr("aria-haspopup").off(this.kG);this.BS(a);g(a).off(this.kG);this.Eaa=!1},r8:function(){var a=this.s8(this.options.menu);if(!a)throw Error('JET Button: "menu" option specified, but does not reference a valid JET Menu.');if(!this.Eaa){var b=this;a.widget().on("ojclose"+this.kG,function(a){b.nAa(a)});this.Eaa=!0}return a},s8:function(b){return(b=a.Components.Yc(g(b)[0],"ojMenu"))&&
b("instance")},Cda:function(a,b){if(!this.Zf()){var c=this.r8(),d=c.widget();c.open(a,{launcher:this.element,initialFocus:b});d.is(":visible")&&(this.Gaa=!0,d.attr("aria-label")||d.attr("aria-labelledby")||(this.element.uniqueId(),this.Tca=!0,d.attr("aria-labelledby",this.element.attr("id"))),this.lc.addClass("oj-selected").removeClass("oj-default oj-focus-only"))}},BS:function(a,b){if(this.Gaa){var c=this.s8(a);c&&(c.ZH(b,!0),c.av(b))}},nAa:function(){this.Tca&&(g(this.options.menu).removeAttr("aria-labelledby"),
this.Tca=!1);this.lc.removeClass("oj-selected");this.Zl();this.Gaa=!1},Zl:function(){var a,b;this.lc.is(".oj-hover, .oj-active, .oj-selected, .oj-disabled")?b=a=!1:(b=this.lc.is(".oj-focus"),a=!b);this.lc.toggleClass("oj-default",a);this.lc.toggleClass("oj-focus-only",b)}});a.Ra("oj.ojButtonset",g.oj.baseComponent,{jaa:"button, input[type\x3dbutton], input[type\x3dsubmit], input[type\x3dreset], input[type\x3dcheckbox], input[type\x3dradio], a",widgetEventPrefix:"oj",options:{checked:null,chroming:"full",
focusManagement:"oneTabstop"},IE:function(a,b){var c=g.type(a),d;if("null"===c||"array"===c)d=b.filter("input[type\x3dcheckbox]").length===b.length;if(d&&"null"===c)throw Error("Invalid 'checked' value set on JET Buttonset: "+a);if("string"===c||"null"===c)(c=((c=b[0].name)||1>=b.length)&&b.filter("input[type\x3dradio][name\x3d"+c+"]").length===b.length&&(null===a||b.filter("[value\x3d"+a+"]").length))&&b.each(function(){this.checked=this.value===a}),c=c||null===a;else if("array"===c){var e;(c=d&&
a.concat().sort().every(function(a){var c=a!==e&&b.filter("[value\x3d"+a+"]").length;e=a;return c}))&&b.each(function(){this.checked=-1<a.indexOf(this.value)})}else c=!1;if(!c)throw Error("Invalid 'checked' value set on JET Buttonset: "+a);},y7:function(a){var b=void 0,c=null,d=null;a.each(function(){if("input"!==this.tagName.toLowerCase())return b=void 0,!1;var a=this.type.toLowerCase(),e;if("radio"===a)a=!0,e=this.name.toLowerCase();else if("checkbox"===a)a=!1,e=null;else return b=void 0,!1;if(void 0!==
b&&(a!==c||e!==d||c&&!d))return b=void 0,!1;void 0===b?(b=a?this.checked?this.value:null:this.checked?[this.value]:[],c=a,d=e):this.checked&&(c?b=this.value:b.push(this.value))});return b},TB:function(a,b,c){return"checked"===a?b===c?!0:"array"===g.type(b)&&"array"===g.type(c)&&this.xra(b,c):this._superApply(arguments)},xra:function(a,b){return!a.some(function(a){return 0>b.indexOf(a)})&&!b.some(function(b){return 0>a.indexOf(b)})},Yf:function(a,b){this._super(a,b);this.Df=this.element.find(this.jaa);
if(!("checked"in b)){this.mZ=!0;var c=this.y7(this.Df);"array"===g.type(c)&&(this.options.checked=[]);void 0!==c&&this.option("checked",c,{_context:{kb:!0}})}},_ComponentCreate:function(){this._super();this.element.attr(a.Components.po,this.widgetName).addClass("oj-buttonset oj-component");this.pda(this.options.focusManagement);this.ab(!0)},ph:function(a,b,c){a=this.element.find(":oj-button[tabindex\x3d0]");this.qh(b,c,{launcher:a,position:{of:"keyboard"===c?a.ojButton("widget"):b}})},et:function(a){a=
!!a;this.Df.each(function(){g(this).data("oj-ojButton").lC(a)})},pda:function(a){"oneTabstop"===a?this.element.attr("role","toolbar"):this.element.removeAttr("role")},_setOption:function(a,b,c){this._superApply(arguments);"disabled"===a?this.et(b):"checked"===a?(this.IE(b,this.Df),this.Df.each(function(){g(this).data("oj-ojButton").iI(!1)})):"focusManagement"===a?this.pda(b):"chroming"===a&&(d(this.element,b),this.Df.ojButton("refresh"))},refresh:function(){this._super();this.ab(!1)},ab:function(a){var b=
this;this.jl="rtl"===this.nd();d(this.element,this.options.chroming);a?this.mZ||this.IE(this.options.checked,this.Df):this.Df=this.element.find(this.jaa);this.element.toggleClass("oj-buttonset-multi",1<this.Df.length);this.Df.filter(":oj-button").ojButton("refresh").each(function(){g(this).data("oj-ojButton").iI(!1)}).end().not(":oj-button").ojButton().end().map(function(){return g(this).ojButton("widget")[0]}).removeClass("oj-buttonset-first oj-buttonset-last").filter(":first").addClass("oj-buttonset-first").end().filter(":last").addClass("oj-buttonset-last").end().end();
this.et(this.options.disabled);"oneTabstop"===this.options.focusManagement&&(this.Df.unbind("keydown"+this.eventNamespace).bind("keydown"+this.eventNamespace,function(a){b.Ev(a,g(this))}).unbind("click"+this.eventNamespace).bind("click"+this.eventNamespace,function(){g(this).data("oj-ojButton").Zf()||b.ow(g(this))}).unbind("focus"+this.eventNamespace).bind("focus"+this.eventNamespace,function(){b.ow(g(this))}),this.Vp=this.Df.filter(function(){return!g(this).data("oj-ojButton").Zf()}),this.YU(a))},
YU:function(a){var b=g(this.Uv);this.Uv=void 0;this.Df.attr("tabindex","-1");a=a||!b.is(this.Vp)?this.Vp.first():b;this.ow(a)},yV:function(a){var b=this.Vp;return a.map(function(a,d){if("radio"!=d.type||d.checked||""==d.name)return d;var e=c(d,b).filter(":checked");return e.length?e[0]:d})},ow:function(a){a=this.yV(a);var b=a[0],c=this.Uv;b!==c&&(g(c).attr("tabindex","-1"),a.attr("tabindex","0"),this.Uv=b)},Ev:function(a,b){switch(a.which){case g.ui.keyCode.LEFT:case g.ui.keyCode.RIGHT:a.preventDefault();
var c=this.Vp,d=c.length;if(2>d)break;var e=c.index(b);c.eq((e+(a.which==g.ui.keyCode.RIGHT^this.jl?1:-1)+d)%d).focus();break;case g.ui.keyCode.UP:case g.ui.keyCode.DOWN:"radio"==b.attr("type")&&a.preventDefault()}},_destroy:function(){this.element.removeClass("oj-buttonset oj-component "+r).removeAttr(a.Components.po).removeAttr("role");"oneTabstop"===this.options.focusManagement&&this.Df.attr("tabindex","0");this.Df.map(function(){return g(this).ojButton("widget")[0]}).removeClass("oj-buttonset-first oj-buttonset-last").end().ojButton("destroy")}});
var e,f,h=".ojButton",k="oj-button oj-component oj-enabled oj-default",l="oj-hover oj-active oj-selected",m="oj-button-icons-only oj-button-icon-only oj-button-text-icons oj-button-text-icon-start oj-button-text-icon-end oj-button-text-only",r="oj-button-full-chrome oj-button-half-chrome oj-button-outlined-chrome",t={full:"oj-button-full-chrome",half:"oj-button-half-chrome",outlined:"oj-button-outlined-chrome"},s={button:["ojButtonset","ojToolbar"],buttonset:["ojToolbar"]};a.Components.Wn({ojButton:{chroming:a.Components.Ne(function(a){return b("button",
a.element,a.containers)})},ojButtonset:{chroming:a.Components.Ne(function(a){return b("buttonset",a.element,a.containers)})}})})();a.Components.Xa("ojButton","baseComponent",{properties:{chroming:{type:"string"},disabled:{type:"boolean"},display:{type:"string"},icons:{type:"Object"},label:{type:"string"},menu:{type:"string"}},methods:{destroy:{},refresh:{},widget:{}},extension:{_hasWrapper:!0,_innerElement:"button",_widgetName:"ojButton"}});a.Components.register("oj-button",a.Components.getMetadata("ojButton"));
a.Components.Xa("ojToggleButton","baseComponent",{properties:{chroming:{type:"string"},disabled:{type:"boolean"},display:{type:"string"},icons:{type:"Object"},label:{type:"string"},menu:{type:"string"}},methods:{destroy:{},refresh:{},widget:{}},extension:{_hasWrapper:!0,_defaultAttrs:{type:"checkbox"},_innerElement:"input",_widgetName:"ojButton"}});a.Components.register("oj-toggle-button",a.Components.getMetadata("ojToggleButton"));a.Components.Xa("ojButtonset","baseComponent",{properties:{checked:{type:"string|Array\x3cstring\x3e"},
chroming:{type:"string"},disabled:{type:"boolean"},focusManagement:{type:"string"}},methods:{destroy:{},refresh:{},widget:{}},extension:{_widgetName:"ojButtonset"}});a.Components.register("oj-buttonset",a.Components.getMetadata("ojButtonset"))});